package SwordOffer2;

public class day8_1 {
    /*
    * 反转链表：双指针
    * 1.创建指针pre，cur，cur=head
    * 2.创建临时节点next=cur.next，cur.next指向pre，向后移动cur，pre
    * 3.cur为空时退出循环，返回pre。
    * */
    public ListNode reverseList(ListNode head) {
        ListNode pre = null;
        ListNode cur = head;
        while(cur!=null) {
            ListNode next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }
        return pre;
    }
}
